Some support for linking is present in two of the sample parts, ODFDraw and ODFTable. Here are the differences between the two:
ODFDraw
- permits only one link to be created from a given shape
- permits creating a link by cmd-dragging
- doesn't support link selection
- doesn't show link borders
ODFTable
- a cell can be the source for multiple links
- doesn't allow creating a link by cmd-dragging
- a link is automatically selected when its cell is selected
- shows link borders only when the "Show Links" box is checked in the Document Info dialog
The “Paste As” Menu Command
The “Paste As” menu item is enabled by ODF in FW_CFrame::HandleAdjustMenus whenever the clipboard contains a link spec. You may wish to impose more conditions for enabling this command; for example, CTableFrame::DoAdjustMenus doesn't enable pasting when the selected cell is already occupied.
ODFDraw: the Paste As command is undoable, and is implemented in CDrawClipboardCommand.
ODFTable: the Paste As command is undoable, and is implemented in CTableEditCommand.
Paste As Via Cmd-dragging
ODFDraw: see the class CDrawDropCommand. Note that it overrides DoDroppedPasteAs, which is called after the drop/PasteAs has already occurred. Another point of interest is that code for undo/redo of the two PasteAs commands is shared in the CDrawLinkManager methods UndoPasteAs and RedoPasteAs.
Show Link Info
ODFTable: CTableFrame overrides ShowPartInfo to show link info when the selected cell contains a part that's in a link. See CTableLinkManager::ShowLinkInfo. The appropriate link info dialog is shown in CTableLinkSource::DoLinkInfo, and CTableLink::DoLinkInfo.
Breaking Links
ODFTable: Links may be broken by clicking on the “Break Link” button in the Link Info dialog. The DoLinkInfo methods in CTableLink and CTableLinkSource create the undo-able commands CBreakLinkSourceCommand and CBreakLinkCommand. These command objects are returned to CTableLinkManager::ShowLinkInfo, which executes them.
Link Borders
ODFTable: Link borders are displayed when the "Show Links" box is checked in the Document Info window. (Note: you may have to move the grid lines to get them to show up.) CTableFrame::Draw checks the window's ShowLinks flag, and if it's set, iterates through the links and tells them to draw their link borders. See the override methods DoCreateLinkBorderShape and DoDrawLinkBorder in CTableLink and CTableLinkSource for an example of drawing link borders.
Link Selection
ODFTable: Links are automatically selected when their cell is selected. Selecting a link by clicking on its border is not yet implemented.